package com.whenjun.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.ifootbook.util.NetUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

@Configuration
@EnableKnife4j
public class Swagger3Config {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors
				.withMethodAnnotation(ApiOperation.class))
				.paths(PathSelectors.any())
				.build()
		// 支持的通讯协议集合
        .protocols(NetUtil.getCurrentProtocols());
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("接口文档").description("")
				.contact(new Contact("", "", "584485799@qq.com")).version("1.0")
				.termsOfServiceUrl("")
				.licenseUrl("")
				.build();
	}
	
	
    @SafeVarargs
    private final <T> Set<T> newHashSet(T... ts) {
        if (ts.length > 0) {
            return new LinkedHashSet<>(Arrays.asList(ts));
        }
        return null;
    }
}
